#pragma once

#include <string>
#include <string_view>
#include <fstream>
#include <mutex>
#include <filesystem>

namespace axon_logger {
namespace io {

class RotatingFileWriter {
public:
    RotatingFileWriter(const std::string& base_filename, size_t max_file_size, size_t max_files);
    ~RotatingFileWriter();

    void write(std::string_view message);

private:
    void open_file();
    void rotate();

    std::mutex m_mutex;
    std::filesystem::path m_baseFilePath;
    size_t m_maxFileSize;
    size_t m_maxFiles;
    size_t m_currentFileSize;
    std::ofstream m_fileStream;
};

} // namespace io
} // namespace axon_logger

